package com.mcxx.ansync.listener;

import com.mcxx.modules.supervise.event.SuperviseLogEvent;
import com.mcxx.modules.supervise.service.write.SuperviseLogWriteService;
import com.mcxx.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;


@Component
public class SuperviseLogListener {
    private final static Logger logger = LoggerFactory.getLogger(SuperviseLogListener.class);
    @Autowired
    protected SuperviseLogWriteService superviseLogService;

    @Async
    @EventListener
    public void saveEventResultLog(SuperviseLogEvent superviseLogEvent) throws InterruptedException {
        Thread.sleep(1000);
        logger.info("记录异步消息，superviseLogEvent: {}, {}", superviseLogEvent, DateUtil.now());
        superviseLogService.insert(superviseLogEvent.getSuperviseLogDTO(), superviseLogEvent.getUserAccountVo());
    }
}
